;
(function (window, angular) {
    'use strict';
    let getTranslateRes;
    const filterApp = angular.module("Filter.All", []);
    filterApp.run(['$translate', '$state', function($translate, $state) {
        getTranslateRes = function(val) {
            return $state.current.is18n && val ? $translate.instant(val) : val;
        }
    }])

    filterApp.filter('isHeader', function () {
        return function (dataArray) {
            var outPut = [];
            angular.forEach(dataArray, function (item) {
                if (item.IsHeader && item.IsChecked) {
                    outPut.push(item);
                }
            });
            return outPut;
        }
    })

    filterApp.filter('isFoot', function () {
        return function (dataArray) {
            var outPut = [];
            angular.forEach(dataArray, function (item) {
                if (!item.IsHeader && item.IsChecked) {
                    outPut.push(item);
                }
            });
            return outPut;
        }
    })

    filterApp.filter("convertMMToPx", function () {
        return function (mmValue) {
            var pxValue = 0;
            if (angular.isString(mmValue)) {
                mmValue = parseFloat(mmValue);
            }
            pxValue = Math.round(mmValue * 96 / 25.4);
            return pxValue;
        };
    })
    // 字符串批量查
    filterApp.filter("replaceN", function () {
        //替换换行\n
        return function (value) {
            if (!value) return value
            if (typeof value != 'string') return value
            if (value.indexOf('\n') == -1) return value
            return (value).replace(/\r|\n/ig,",")
        };
    })
    // 数组批量查
    filterApp.filter("replaceNArray", function () {
        //替换换行\n
        return function (value) {
            if (!value) return value
            value = value.replace(/，/g,",")
            if (typeof value != 'string') return value
            // if (value.indexOf('\n') == -1) return value
            value =  (value).replace(/\r|\n/ig,",")
            return value.split(",")
        };
    })

    // 海外公司有,的公司 与 批量查公用一个字段 单查的时候转为数组
    filterApp.filter("batchArray", function () {
        //替换换行\n
        return function (value) {
           if (!value) return []
           let arr = []
           let str = angular.copy(value)
           arr.push(str)
           return arr
        };
    })

    // 海外公司有,的公司 批量查时候转为数组
    filterApp.filter("batchArrayList", function () {
        //替换换行\n
        return function (value) {
           if (!value) return []
           let str = angular.copy(value)
           // 批量查为多公司继续以换行符切割
           if (str.includes("\n")) {
            let arr = str.split("\n")
            return arr
           }else {
            let arr = []
            let str = angular.copy(value)
            arr.push(str)
            return arr
           }
        };
    })
    filterApp.filter("convertCMToPx", ['$filter', function ($filter) {
        return function (cmValue) {
            var pxValue = 0;
            if (angular.isString(cmValue)) {
                cmValue = parseFloat(cmValue);
            }
            pxValue = $filter('convertMMToPx')(cmValue * 10);
            return pxValue;
        };
    }])

    filterApp.filter('ybTrustHtml', ['$sce', function ($sce) {
        return function (text) {
            return $sce.trustAsHtml(text);
        }
    }])

    filterApp.filter("decimalPlaces", function () {
        return function (val, places) {
            // todo 完善小数保留位数
            if (!!val) {
                var result = val.toFixed(places);
                return result;
            } else {
                return val;
            }
        }
    })

    filterApp.filter("decimalCover", function () {
        return function (val, places) {
            var m = Math.pow(10, places);
            val = Math.round(val * m) / m;
            if (!val) {
                return 0;
            }
            var fillSeats = "";
            var valArr = val.toString().split(".");
            if (valArr.length == 1 && places > 0) {
                fillSeats = ".";
                for (var i = 0; i < places; i++) {
                    fillSeats += "0";
                }
                val = val.toString() + fillSeats;
            }

            if (valArr.length > 1 && valArr[1].length < m) {
                for (var i = valArr[1].length; i < places; i++) {
                    fillSeats += "0";
                }
                val = val.toString() + fillSeats;
            }
            return val;
        }
    })

    filterApp.filter("FileDisplay", ['$filter', function ($filter) {
        var IMGTYPE = ".jpeg,.png,.jpg";
        return function (file, sizeParam) {
            if (!file) {
                return
            }
            var fileName = file.FileName.split(".");
            var fileType = fileName[fileName.length - 1];
            if (IMGTYPE.indexOf(fileType) > -1) {
                return $filter('ImgUrl')(file.Key, sizeParam);
            } else {
                switch (fileType) {
                    case "pdf":
                        return "assets/img/file/pdf.png";
                    case "doc":
                        return "assets/img/file/word.png";
                    case "docx":
                        return "assets/img/file/word.png";
                    case "wps":
                        return "assets/img/file/wps.png";
                    default:
                        return;
                }
            }
        }
    }])

    filterApp.filter("ImgUrl", ['ybHttp', function (ybHttp) {
        return function (url, sizeParam, type) {
            if (!url) {
                if (!type) {
                    return "assets/img/default.jpg";
                } else {
                    return "assets/img/icon_user.png";
                }
            }
            return ybHttp.ImgUrl(url, sizeParam, type);
        };
    }])

    filterApp.filter("ApiUrl", ['ybConfig', function (ybConfig) {
        return function (url) {
            return ybConfig.getConfig().baseUrl.Site + url;
        };
    }])

    filterApp.filter("YbNull", function () {
        return function (val) {
            if (val === 0) {
                return 0;
            }
            if (!val) {
                return '-';
            }
            return val;
        }
    })

    filterApp.filter("YbDate", ['$filter', function ($filter) {
        return function (val, format) {
            if (!val) {
                return "";
            }
            if (!format) {
                format = "yyyy-MM-dd";
            }

            var result = $filter("date")(val, format);
            return result;
        }
    }])

    filterApp.filter("DictZhTranslate", function () {
        return function (val) {
            if (!val) {
                return "";
            }
            return getTranslateRes(val);
        }
    })

    filterApp.filter("YbWeek", function () {
        return function (val, format) {
            if (!val) {
                return "";
            }
            var date = new Date(val);
            var weekday = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
            var result = weekday[date.getDay()];
            return getTranslateRes(result);
        }
    })

    filterApp.filter("CreateWay", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "采购申请";
                    break;
                case 1:
                    res = "手动创建";
                    break;
                case 2:
                    res = "外部接口创建";
                    break;
                case 3:
                    res = "合同协议";
                    break;
                default:
                    res = "手动创建";
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("SettleType", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "按订单结算";
                    break;
                case 1:
                    res = "按金额结算";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("CompanyDealerStatus", function () {
        return function (val) {
            let res
            switch (val) {
                case 1:
                    res = "正常维护";
                    break;
                case 2:
                    res = "已流失";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("VehStatus", function () {
        return function (val) {
            let res
            switch (val) {
                case 1:
                    res = "在保";
                    break;
                case 2:
                    res = "出保";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("SaleType", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "其他渠道";
                    break;
                case 1:
                    res = "服务人员渠道";
                    break;
                case 2:
                    res = "电商渠道";
                    break;
                case 3:
                    res = "专营店渠道";
                    break;
                case 4:
                    res = "展会渠道";
                    break;
                case 5:
                    res = "电话渠道";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("WayBillStatus", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "已保存";
                    break;
                case 1:
                    res = "已提交";
                    break;
                case 2:
                    res = "审核通过";
                    break;
                case -1:
                    res = "审核拒绝";
                    break;
                case -2:
                    res = "已删除";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("WayBillStatus2", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "已保存";
                    break;
                case 1:
                    res = "已提交";
                    break;
                case 2:
                    res = "审核通过";
                    break;
                case -2:
                    res = "审核拒绝";
                    break;
                case 3:
                    res = "审批通过";
                    break;
                case -3:
                    res = "审批拒绝";
                    break;
                case -1:
                    res = "已删除";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("packageMethod", function () {
        return function (val) {
            let res
            switch (val) {
                case "1":
                    res = "纸箱";
                    break;
                case "2":
                    res = "木箱";
                    break;
                case "3":
                    res = "托盘";
                    break;
                case "4":
                    res = "裸装";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("GcOrderType", function () {
        return function (val) {
            let res
            switch (val) {
                case "01":
                    res = "资材订单";
                    break;
                case "02":
                    res = "备件订单";
                    break;
                case "03":
                    res = "零件订单";
                    break;
                case "04":
                    res = "例外订单";
                    break;
                case "05":
                    res = "样件订单";
                    break;
                case "06":
                    res = "售后订单";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res)
        }
    })
    filterApp.filter("orderType", function () {
        return function (val) {
            let res
            switch (val) {
                case "GCFR":
                    res = "其它入库";
                    break;
                case "GCFT":
                    res = "发货通知";
                    break;
                case "GCFC":
                    res = "其它出库";
                    break;
                case "GCLL":
                    res = "领料单";
                    break;
                case "GCQD":
                    res = "区域调拨";
                    break;
                case "GCDB":
                    res = "代理商间调拨";
                    break;
                case "GCCX":
                    res = "冲销入库";
                    break;
                case "GCTH":
                    res = "退货入库";
                    break;
                case 'GCFJ':
                    result = "发运交接单";
                case "GCSC":
                    res = "三包出库";
                    break;
                case "GCCI":
                    res = "采购入库";
                    break;
                case "GCQR":
                    res = "期初入库";
                    break;
                case "GCPS":
                    res = "配送指令入库";
                    break;
                case "GCHI":
                    res = "回购入库";
                    break;
                case "GCHI":
                    res = "回购入库";
                    break;
                case "GCCC":
                    res = "销售订单";
                    break;
                case "GCSB":
                    res = "三包申请";
                    break;
                case "GCJY":
                    res = "借用出库";
                    break;
                case "XSCK":
                    res = "销售赠送出库";
                    break;
                case "GCHO":
                    res = "回购出库";
                    break;
                case "GCJI":
                    res = "借用退回入库";
                    break;
                case "GCZX":
                    res = "装箱出库";
                    break;
                case "GCQY":
                    res = "前移库调拨申请";
                    break;
                case "GCZK":
                    res = "赠送出库";
                    break;
                case "ZBD":
                    res = "转包入库";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("ProgressStatus", function () {
        var filterMsg = {
            normal: ["未开始", "进行中", "已完成", "强制结单"],
            returnStatus: ["未发货", "已发货", "已收货"],
            deliveryStatus: ["未发货", "已发货", "已签收", "拒绝签收", "部分发货"],
            logisticStatus: ["", "已发货", "运输中", "已到货", "已签收"],
            outDepot: ["未出库", "部分出库", "已出库", "强制结单"],
            inDepot: ["未入库", "部分入库", "已入库", "强制结单"],
            inventoryState:["未盘点", "盘点启动", "盘点结束"],
            inventoryStatus:["未盘点", "盘点启动", "盘点结束"],
            inStore: ["未入库", "部分入库", "已入库"], // 借用单入库状态
            outStore: ["未出库", "部分出库", "已出库"], // 归还单出库状态
            outStatus: ["未出库", "部分出库", "已出库"], //三包明细出库状态
            transforOut: ["未转出", "部分转出", "全部转出"], // 转入转出状态
            transforIn: ["未转入", "部分转入", "全部转入"], // 转入转出状态
            borrowBackAudit: ["待审核", "审核通过", "审核拒绝", "完成"], // 归还单审批意见
            audit: ["待审核", "审核通过", "审核拒绝", "审核撤销"],
            auditDeliveryNotice: ["","待审核", "审核通过", "审核拒绝"],
            returnAudit: ["草拟", "待审核", "审核通过", "审核拒绝"],
            reverse: ["未冲销", "待审核", "审核通过", "审核拒绝"],
            returnState: ["未退货", "退货中", "退货完成"],
            returnApply: ["未申请", "部分申请", "全部申请"],
            posting: ["未过账", "部分过账", "已过账"],
            sap: ["未同步", "同步成功", "同步失败"],
            sellIntentionSyncNsStatus: ["未同步", "已同步"],
            syncNsStatus: ["未同步", "已同步", "部分同步"],
            verifyState: ["草稿", "未完成", "调出通过", "调出驳回", "调入通过", "调入驳回"],
            checkType: ["根据仓库", "根据保管员", "根据库区", "根据零件","根据仓库类型"],
            synStatus: ["未同步", "同步成功", "同步失败", "不需同步"],
            postingState: ["未过账", "已过账", "过账失败"],
            auditState: ["未审核", "第一步审核拒绝", "第一步审核通过", "第二步审核拒绝", "第二步审核通过"],
            checkState: ["未结算", "部分结算", "已结算"],
            signState: ["未签收", "已签收", "拒绝签收", "异常签收"],
            receiptState: ["未回执", "已回执"],
            sendState: ["未创建", "部分创建", "已创建"],
            exhibitionAuditStatus: ["", "草拟", "待审核", "初审通过", "终审通过", "返回修改", "已完结"],
            exhibitionStatus: ["未开始", "进行中", "展会结束", "驳回", "完结"],
            auditStatus: ["待审核", "审核通过", "审核拒绝"],
            allotPlanStatus: ["编辑", "已提交", "部分调拨", "结单", "已完成"],
            isBorrow: ["拆", "借"],
            isReceive: ["未收货", "已收货"],
            isReceive2: ["未收货", "部分收货", "全部收货"],
            purchaseDeliveryStatus: ["未发货", "已发货", "部分发货"],
            outInvoice: ["未出库", "部分出库", "已出库", "强制完成"],
            socialApplyStatus:["待提交", "待审核", "调度通过", "调度拒绝", "审核通过", "审核拒绝"],
            socialPurchaseReason:["停产", "周期长", "价格高", "无拆分件", "其他原因"],
            checkStatus:["未结算", "已结算"],
            inOutType:["", "入库", "出库"],
            reconciliationStatus:["待确认", "已同意", "已拒绝"],
            boxupPackStatus:["未审核", "通过", "拒绝"],
            createdStatus:["未创建","进行中","已完成"],
            applyOrgNameStatus:["草稿","待审核","已审核","审核驳回","已结单"],
            takeDeliveryStatus:["未提货","已提货"],
            takeDeliveryStatus2:["未提货", "部分提货", "全部提货"],
            ticketStatus:["未开票","已开票"],
            priceChangeInstru:["未完成","已完成"],
            priceChangeState:["", "升","降"],
            priceChangeDB:["未督办","已督办"],
            //add by lqx
            deleteState:["否","是"],
            warnType:["-","承运商未按时上传签收单","代理商未按时签收"],
            dbFlag:["否","是"],
            warnNoteStatus:["未完成","已完成"],
            distributionType:["-","自营","收购"],
            commentState: ['未评价', '已评价'],
            vehicleState: ['待认证', '已认证', '驳回', '失效'],
            supplierState: ['草稿', '待审核', '审核拒绝', '审核通过'],
            crmState: ['未传输', '已传输'],
            fwdAudit: ['待审核', '审核通过', '审核拒绝', '无需审核'],
            fwdAudit2: ['未开始', '提交一级审核', '一级审核拒绝', '一级审核通过', '二级审核拒绝', '二级审核通过'],
            generateState: ['否', '是', '部分创建'],
            stockAddStatus: ['未审批', '已通过', '驳回'],
            dscStatus: ['未推送', '已推送', '推送失败'],
            ticketState:["未开票","已开票"],
            stopFlag:['启用','停用'],
            subOrderStatus:["已创建", "部分入库", "已入库"],
        };
        var type = "";
        return function (val, param) {
            if (!isNaN(val)) {
                val = parseInt(val);
            }
            type = !!param ? param : "normal";
            let res = filterMsg[type][val] || '-';
            return getTranslateRes(res)
        }
    })

    filterApp.filter("wjReport", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 'bn':
                    result = "保内";
                    break;
                case 'bw':
                    result = "保外";
                    break;
            }
            return result;
        }
    })

    filterApp.filter("isBorrow", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "拆";
                    break;
                case 1:
                    result = "借";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("BusinessType", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 'GCFJ':
                    result = "发运交接单";
                    break;
                case 'GCSC':
                    result = "三包出库单";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("TrueOrFalse", function () {
        var filterMsg = {
            normal: ["否", "是"],
            sex: ["女", "男"],
            lockStatues: ["启用", "锁定"],
            status: ["停用", "启用"],
            enabled: ["禁用", "启用"],
            inOut: ["入库类型", "出库类型"],
            priceScheme: ["固定折扣", "指定价格"],
            schemeType: ["常规", "价格折让", "促销活动"],
        };
        var type = "";
        return function (val, param) {
            type = !!param ? param : "normal";
            let res = filterMsg[type][val] || filterMsg[type][0];
            return getTranslateRes(res);
        }
    })

    filterApp.filter("TrueOrFalseOrNull", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                case "0":
                case false:
                    result = "否";
                    break;
                case 1:
                case "1":
                case true:
                    result = "是";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("ReplaceEnabled", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                case "0":
                    result = "启用";
                    break;
                case 1:
                case "1":
                    result = "禁用";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("ReplaceDirection", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 1:
                case "1":
                    result = "单向";
                    break;
                case 2:
                case "2":
                    result = "双向";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("printState", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "未打印";
                    break;
                case 1:
                    result = "部分打印";
                    break;
                case 2:
                    result = "已打印";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("allotState", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "未完成";
                    break;
                case 1:
                    result = "部分完成";
                    break;
                case 2:
                    result = "已完成";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("checkState", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "正常";
                    break;
                case 1:
                    result = "盘亏";
                    break;
                case 2:
                    result = "盘盈";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("inventoryCheck", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "未盘点";
                    break;
                case 1:
                    result = "盘点启动";
                    break;
                case 2:
                    result = "盘点结束";
                    break;
                case 3:
                    result = "盘点终止";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter("allocationRole", function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "创建方";
                    break;
                case 1:
                    result = "调出方";
                    break;
                case 2:
                    result = "调入方";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    filterApp.filter('storageType', function () {
        return function (data) {
            let result = "-";
            switch (data) {
                case 0:
                    result = "正常库存";
                    break;
                case 1:
                    result = "冻结库存";
                    break;
                case 2:
                    result = "非正常库存";
                    break;
                case 3:
                    result = "借用";
                    break;
                case 4:
                    result = "已拆分";
                    break;
            }
            return getTranslateRes(result);
        }
    })

    //拆件类型
    filterApp.filter('DismantlingType', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "总成件";
                    break;
                case 1:
                    res = "整机";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    //拆件状态
    filterApp.filter('DismantlingStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "未开始";
                    break;
                case 1:
                    res = "部分拆件";
                    break;
                case 2:
                    res = "已拆件";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    //原件恢复状态
    filterApp.filter('RestoreStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "未恢复";
                    break;
                case 1:
                    res = "部分恢复";
                    break;
                case 2:
                    res = "已恢复";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    // 额度赠送类型
    filterApp.filter('GiveQuotaTypeStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                    res = "通用";
                    break;
                case 2:
                    res = "保养";
                    break;
                default:
                    res = "通用";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    // 预付款单据类型
    filterApp.filter('PrepPayBillType', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "充值";
                    break;
                case 1:
                    res = "结算";
                    break;
                case 2:
                    res = "退货";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    // 订单类型
    filterApp.filter('BillTypeStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                    res = "普通";
                    break;
                case 2:
                    res = "三包";
                    break;
                case 3:
                    res = "赠送";
                    break;
                case 4:
                    res = "其他";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter('GiveQuotaTypes', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                    res = "通用";
                    break;
                case 2:
                    res = "保养";
                    break;
                default:
                    res = "无";
            }
            return getTranslateRes(res);
        }
    })

    //创建出库单状态
    filterApp.filter('CreateOutboundStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "未创建";
                    break;
                case 1:
                    res = "进行中";
                    break;
                case 2:
                    res = "已完成";
                    break;
                default:
                    res = "未创建";

            }
            return getTranslateRes(res);
        }
    })

    //出库状态
    filterApp.filter('OutboundStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                case '0':
                    res = "未出库";
                    break;
                case 1:
                case '1':
                    res = "部分出库";
                    break;
                case 2:
                case '2':
                    res = "已出库";
                    break;
                case 3:
                case '3':
                    res = "强制结单";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    //出库状态
    filterApp.filter('OutboundStatus2', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                case '0':
                    res = "未出库";
                    break;
                case 1:
                case '1':
                    res = "正在出库";
                    break;
                case 2:
                case '2':
                    res = "已出库";
                    break;
                case 3:
                case '3':
                    res = "强制结单";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    // 销售单状态
    filterApp.filter("Status", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "已保存";
                    break;
                case 1:
                    res = "已提交";
                    break;
                case 2:
                    res = "已出库";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    // 销售单审核状态
    filterApp.filter("CheckFlagStatus", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "审核拒绝";
                    break;
                case 1:
                    res = "审核通过";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    // 审核状态(领料单、其他出库单、其他入库单)
    filterApp.filter("AuditStatus2", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "待审核";
                    break;
                case 1:
                    res = "审核通过";
                    break;
                case -1:
                    res = "审核拒绝";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    //审核状态
    filterApp.filter('AuditStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 0:
                    res = "待审核";
                    break;
                case 1:
                    res = "第一步审核通过";
                    break;
                case 2:
                    res = "第一步审核拒绝";
                    break;
                case 3:
                    res = "第二步审核通过";
                    break;
                case 4:
                    res = "第二步审核拒绝";
                    break;
                case 5:
                    res = "第三步审核通过";
                    break;
                case 6:
                    res = "第三步审核拒绝";
                    break;
                case 7:
                    res = "第四步审核通过";
                    break;
                case 8:
                    res = "第四步审核拒绝";
                    break;
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter('BoxupPackDeliveryStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                case '1':
                    res = "已发运";
                    break;
                case 4:
                case '4':
                    res = "部分发运";
                    break;
                default:
                    res = '未发运'
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter('BoxupPackDetailDeliveryStatus', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                case '1':
                    res = "已发运";
                    break;
                default:
                    res = '未发运'
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter('OpTypePurchase', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                case '1':
                    res = "订单驳回";
                    break;
                case 2:
                case '2':
                    res = "删除订单";
                    break;
                case 3:
                case '3':
                    res = "删除零件";
                    break;
                case 4:
                case '4':
                    res = "调整零件数量";
                    break;
                default:
                    res = ''
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter('OpTypeSell', function () {
        return function (data) {
            let res
            switch (data) {
                case 1:
                case '1':
                    res = "订单删除";
                    break;
                case 2:
                case '2':
                    res = "零件删除";
                    break;
                case 3:
                case '3':
                    res = "零件冻结";
                    break;
                case 4:
                case '4':
                    res = "零件解冻";
                    break;
                case 5:
                case '5':
                    res = "价格调整";
                    break;
                case 6:
                case '6':
                    res = "数量调整";
                    break;
                case 7:
                case '7':
                    res = "零件替换";
                    break;
                default:
                    res = ''
            }
            return getTranslateRes(res);
        }
    })

    filterApp.filter("PayTypeF", function () {
        return function (val) {
            let res
            switch (val) {
                case 1:
                    res = "现金";
                    break;
                case 2:
                    res = "差价";
                    break;
                case 3:
                    res = "承兑";
                    break;
                case 4:
                    res = "融资";
                    break;
                case 5:
                    res = "调账";
                    break;
                case 6:
                    res = "返利";
                    break;
                case 7:
                    res = "服务费";
                    break;
                case 8:
                    res = "报告抵扣";
                    break;
                case 9:
                    res = "易贷";
                    break;
                case 10:
                    res = "三方转账";
                    break;
                case 11:
                    res = "电汇";
                    break;
                case 12:
                    res = "其它";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    // 回款类别
    filterApp.filter("ReMoneyTypeF", function () {
        return function (val) {
            val = String(val)
            let res
            switch (val) {
                case '0':
                    res = "新业务首付款";
                    break;
                case '1':
                    res = "新业务全款";
                    break;
                case '2':
                    res = "分期回款";
                    break;
                case '3':
                    res = "逾期清收";
                    break;
                default:
                    res = "-";
            }
            return getTranslateRes(res);
        }
    })

    .filter("DealerType", function () {
        return function (data) {
            var dataT = String(data);
            var result = "-";
            switch (dataT) {
                case '1':
                    result = "核心企业";
                    break;
                case '2':
                    result = "代理商";
                    break;
                case '3':
                    result = "供货商";
                    break;
                case '4':
                    result = "承运商";
                    break;
                case '5':
                    result = "服务站";
                    break;
                case '20':
                    result = "自建二级代理商";
                    break;
                case '50':
                    result = "自建二级服务站";
                    break;
                default:
                    break;
            }
            return result;
        }
    })

    .filter("Source", function () {
        return function (data) {
            var result = "-";
            switch (data) {
                case 0:
                    result = "手工录入";
                    break;
                case 1:
                    result = "小程序关注";
                    break;
                default:
                    break;
            }
            return result;
        }
    })
    .filter("PayStatus", ['$filter', function ($filter) {
        return function (val) {
            switch (val) {
                case 0:
                case '0':
                    return "待支付";
                case 1:
                case '1':
                    return "已支付";
                case 2:
                case '2':
                    return "已发货";
                case 3:
                case '3':
                    return "确认收货";
                case 4:
                case '4':
                    return "取消";
                default:
                    return "-";
            }
        }
    }])
    // 服务单渠道
    .filter("Channel", ['$filter', function ($filter) {
        return function (val) {
            switch (val) {
                case 1:
                case '1':
                    return "400录入";
                case 2:
                case '2':
                    return "营销部录入";
                case 3:
                case '3':
                    return "服务站录入";
                case 4:
                case '4':
                    return "客户小程序录入 ";
                default:
                    return "-";
            }
        }
    }])
    // 服务单类型
    .filter("ServiceType", ['$filter', function ($filter) {
        return function (val) {
            switch (val) {
                case 1:
                case '1':
                    return "交机前检查服务";
                case 2:
                case '2':
                    return "交机服务";
                case 3:
                case '3':
                    return "主动服务";
                case 4:
                case '4':
                    return "顾客服务";
                case 5:
                case '5':
                    return "改装服务";
                case 6:
                case '6':
                    return "保外顾客服务";
                case 7:
                case '7':
                    return "租赁服务";
                case 8:
                case '8':
                    return "走访服务";
                default:
                    return "-";
            }
        }
    }])
    // 服务单状态
    .filter("RepairState", ['$filter', function ($filter) {
        return function (val) {
            switch (val) {
                case 0:
                case '0':
                    return "作废";
                case 1:
                case '1':
                    return "提交待分单";
                case 10:
                case '10':
                    return "已分单待派工";
                case 20:
                case '20':
                    return "已派工待接单";
                case 30:
                case '30':
                    return "已接单待维修";
                case 35:
                case '35':
                    return "完工暂存";
                case 40:
                case '40':
                    return "已完工";
                default:
                    return "-";
            }
        }
    }])
    // 交通工具
    .filter("Vehicle", ['$filter', function ($filter) {
        return function (val) {
            switch (val) {
                case 1:
                case '1':
                    return "自驾";
                case 2:
                case '2':
                    return "乘车";
                default:
                    return "-";
            }
        }
    }])

    // 距离转换
    .filter("FormatDis", ['$filter', function ($filter) {
        return function (value) {
            if (!value) {
                return '-'
            }
            if (value > 1000) {
                return (value / 1000).toFixed(2) + '公里'
            }
            return Number(value).toFixed(0) + '米'
        }
    }])

    filterApp.filter("WarrantyStatus", function () {
        return function (val) {
            let res
            switch (val) {
                case 0:
                    res = "出保";
                    break;
                case 1:
                    res = "在保";
                    break;
            }
            return getTranslateRes(res)
        }
    })

    filterApp.filter("InvoiceType", function () {
        return function (data) {
            if (!data) {
                return "";
            }

            let result = "负值发票";
            switch (data) {
                case 'ZF2':
                    result = "正常开票";
                    break;
                case 'ZS2':
                    result = "红票作废";
                    break;
            }
            return getTranslateRes(result);
        }
    })
    
    ;
})(window, window.angular);
